package com.csu.income;

import java.util.List;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.math.BigDecimal;
import java.sql.Date;

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.csu.dao.IncomeDao;
import com.csu.dao.IncomeDaoImpl;


public class INewFrame extends JFrame{
	public void initContent(){
		//创建用户名输入面板
//		JLabel moneyLabel = new JLabel("收入金额: ");
//	    //设置坐标和宽高
//		moneyLabel.setBounds(60, 20, 80, 40);
//		JTextField moneyField = new JTextField();
//		moneyField.setBounds(140,20,250,40);
//		JPanel panel1 = new JPanel();
//		//将文本框和输入框加入到面板里
//		panel1.add(moneyLabel);
//		panel1.add(moneyField);
//		panel1.setLayout(null);

		JLabel peopleLabel = new JLabel("收入者: ");
		//设置坐标和宽高
		peopleLabel.setBounds(60, 20, 80, 40);
		JTextField peopleField= new JTextField();
		peopleField.setBounds(140,20,250,40);
		JPanel panel1 = new JPanel();
		//将文本框和输入框加入到面板里
		panel1.add(peopleLabel);
		panel1.add(peopleField);
		panel1.setLayout(null);

		//创建用户名输入面板
		JLabel typeLabel = new JLabel("收入类型: ");
		//设置坐标和宽高
		typeLabel.setBounds(60, 20, 80, 40);
		JComboBox<String> typeBox = new JComboBox<String>();
		String type1 = "工资";
		String type2 = "股票";
		String type3 = "分红";
		String type4 = "奖金";
		typeBox.addItem(type1);
		typeBox.addItem(type2);
		typeBox.addItem(type3);
		typeBox.addItem(type4);
		typeBox.setSelectedItem(type1);
		typeBox.setBounds(140,20,250,40);
		JPanel panel2 = new JPanel();
		//将文本框和输入框加入到面板里
		panel2.add(typeLabel);
		panel2.add(typeBox);
		panel2.setLayout(null);

		//创建用户名输入面板
		JLabel dateLabel = new JLabel("收入日期: ");
		//设置坐标和宽高
		dateLabel.setBounds(60, 20, 80, 40);
		JTextField dateField = new JTextField();
		dateField.setBounds(140,20,250,40);
		JPanel panel3 = new JPanel();
		//将文本框和输入框加入到面板里
		panel3.add(dateLabel);
		panel3.add(dateField);
		panel3.setLayout(null);

		//创建用户名输入面板
		JLabel useLabel = new JLabel("收入来源: ");
		//设置坐标和宽高
		useLabel.setBounds(60, 20, 80, 40);
		JTextField useField = new JTextField();
		useField.setBounds(140,20,250,40);
		JPanel panel4 = new JPanel();
		//将文本框和输入框加入到面板里
		panel4.add(useLabel);
		panel4.add(useField);
		panel4.setLayout(null);

		//创建用户名输入面板
		JLabel moneyLabel = new JLabel("收入金额: ");
		//设置坐标和宽高
		moneyLabel.setBounds(60, 20, 80, 40);
		JTextField moneyField = new JTextField();
		moneyField.setBounds(140,20,250,40);
		JPanel panel5 = new JPanel();
		//将文本框和输入框加入到面板里
		panel5.add(moneyLabel);
		panel5.add(moneyField);
		panel5.setLayout(null);

		//创建用户名输入面板
		JLabel notesLabel = new JLabel("相关备注:");
		//设置坐标和宽高
		notesLabel.setBounds(60, 20, 80, 40);
		JTextField notesField = new JTextField();
		notesField.setBounds(140,20,250,40);
		JPanel panel6 = new JPanel();
		//将文本框和输入框加入到面板里
		panel6.add(notesLabel);
		panel6.add(notesField);
		panel6.setLayout(null);

		JButton btnSubmit = new JButton("提交");
		JButton btnReset = new JButton("重置");
		JPanel panel7 = new JPanel(new FlowLayout(FlowLayout.CENTER));
		panel7.add(btnSubmit);
		panel7.add(btnReset);

		btnSubmit.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				//String moneyStr = moneyField.getText();
				BigDecimal moneyStr = new BigDecimal(moneyField.getText());
				String typeStr = typeBox.getSelectedItem().toString();
				String peopleStr = peopleField.getText();
				Date dateStr = Date.valueOf(dateField.getText());
				String useStr = useField.getText();
				String notesStr = notesField.getText();
				IncomeDao incomeDao = new IncomeDaoImpl();
				incomeDao.addIncome(peopleStr, typeStr, dateStr, useStr, moneyStr, notesStr);
				initContent();
				//隐藏窗口
				setVisible(false);
				ISubFrame iSubFrame = new ISubFrame();
				iSubFrame.setSize(300, 150);
				iSubFrame.setLocationRelativeTo(null);
				iSubFrame.initContent();
			}
		});

		btnReset.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				moneyField.setText("");
				typeBox.setSelectedItem(type1);
				peopleField.setText("");
				dateField.setText("");
				useField.setText("");
				notesField.setText("");

			}

		});

		//创建垂直排列的容器Box
		Box vBox = Box.createVerticalBox();
		vBox.add(panel1);
		vBox.add(panel2);
		vBox.add(panel3);
		vBox.add(panel4);
		vBox.add(panel5);
		vBox.add(panel6);
		vBox.add(panel7);
		//jframe设置内容面板
		setContentPane(vBox);
		//显示窗口
		setVisible(true);

	}

}
